package com.tianjian.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.tianjia.entity.XinWen;
import com.tianjia.uitl.DBManager;

public class XinWenDaoImpl {
	public List<XinWen> getXinWenList(int cId) {
		List<XinWen> list = new ArrayList<XinWen>();//创建新闻集合
		Connection conn = DBManager.getConnection();//创建连接
		//全局变量
		Statement st = null;
		ResultSet rs = null;
		
		try {//正常执行
			//创建Statement执行对象,作用是执行sql语句
			st = conn.createStatement();
			//执行sql语句
			rs = st.executeQuery("select * from xinwen where xinWenId = "+cId);
			//遍历结果集
			while(rs.next()) {
				int audiNewsid= rs.getInt("audiNewsid");
				String xinWenTime= rs.getString("xinWenTime");
				String xinWenBiaoTi= rs.getString("xinWenBiaoTi");
				String xinWenNeiRong= rs.getString("xinWenNeiRong");
				int xinWenId= rs.getInt("xinWenId");
				//创建新闻对象
				XinWen xinwen = new XinWen(audiNewsid,xinWenTime,xinWenBiaoTi,xinWenNeiRong,xinWenId);
				list.add(xinwen);//把xinwen对象放进list中
			}
			return list;//正常情况下返回list
		} catch (SQLException e) {//异常执行
			e.printStackTrace();
			return null;//异常情况下执行
		}finally { //关闭流
			DBManager.closeAll(conn, st, rs);
		}
	}
}
